package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.vo.request.MessageSearchVo;
import com.zhijian.medical.entity.vo.response.MessageVo;
import com.zhijian.medical.enums.MessageReceiveTypeEnum;
import com.zhijian.medical.enums.MessageWeatherReadEnum;
import com.zhijian.medical.service.MessageService;
import com.zhijian.medical.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息通知 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2022-06-07 15:41:53
 */
@Slf4j
@Controller
@Api(tags = "消息通知")
public class MessageController {

    @Autowired
    private MessageService service;

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/message/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 批量删除
     *
     * @return
     */
    @Response
    @DeleteMapping("/message/list")
    @ApiOperation("批量删除")
    public boolean delete(@RequestBody List<Long> idList) {
        service.deleteByIdList(idList);
        return true;
    }

    /**
     * 获取新的消息通知列表
     *
     * @return
     */
    @Response
    @GetMapping("/message/list")
    @ApiOperation("获取新的消息通知列表")
    public List<MessageVo> selectList() {
        return service.selectList(MessageSearchVo.builder()
                .receiveType(MessageReceiveTypeEnum.PC.getCode().byteValue())
                .weatherRead(MessageWeatherReadEnum.UN_READ.getCode().byteValue())
                .build());
    }

    /**
     * 忽略or已读
     *
     * @return
     */
    @Response
    @PutMapping("/message/{id}")
    @ApiOperation("忽略or已读")
    public boolean read(@PathVariable("id") Long id) {
        service.read(id);
        return true;
    }

    /**
     * 批量忽略or已读
     *
     * @return
     */
    @Response
    @PutMapping("/message/list")
    @ApiOperation("批量忽略or已读")
    public boolean read(@RequestBody List<Long> idList) {
        service.read(idList);
        return true;
    }

    /**
     * 获取全部的分页消息数据
     *
     * @return
     */
    @Response
    @PostMapping("/message/list/page")
    @ApiOperation("获取全部的分页消息数据")
    public Page<MessageVo> selectList(@RequestBody MessageSearchVo messageSearchVo) {
        messageSearchVo.setReceiveType(MessageReceiveTypeEnum.PC.getCode().byteValue());
        return service.selectPage(messageSearchVo);
    }

}